<template>
  <el-dialog title="详情" :visible.sync="show" append-to-body width="500px" @closed="closed">
    <div v-loading="infoLoading" element-loading-background="rgba(255, 255, 255, 0.5)">
      <el-empty v-if="!info.fid && !infoLoading" :image-size="100" />
      <div v-else>
        <el-descriptions :column="1" size="small" border :label-style="{ width: '80px' }">
          <el-descriptions-item label="文件名">{{ info.fileName }}</el-descriptions-item>
          <el-descriptions-item label="上传人">{{ info.creatorName }}</el-descriptions-item>
          <el-descriptions-item label="上传时间">{{ info.createTime }}</el-descriptions-item>
          <el-descriptions-item label="业务类型" v-if="info.belongBuss">{{ info.belongBuss }}</el-descriptions-item>
          <el-descriptions-item label="描述">{{ info.description }}</el-descriptions-item>
        </el-descriptions>
      </div>
    </div>
  </el-dialog>
</template>
<script>
// 文件详情
import { getProjectAlbum } from '@/api/baseManage/projectAlbum'
export default {
  data() {
    return {
      show: false,
      currFile: {},
      infoLoading: false,
      info: {}
    }
  },
  methods: {
    closed() {
      this.currFile = {}
      this.info = {}
    },
    open(data) {
      if (!data.fid) return this.msgError('参数错误：文件ID不能为空')
      this.show = true
      this.currFile = data
      if (data.fileInfo) return (this.info = data.fileInfo)
      this.getInfo()
    },
    async getInfo() {
      const item = this.currFile
      const opt = {
        pageSize: 1,
        projectId: item.projectId,
        businessType: item.businessType,
        parentId: `${item.ancestorIds},${item.fid}`,
        ftype: item.ftype,
        detailType: item.detailType,
        detailId: item.detailId
      }
      this.infoLoading = true
      const res = await getProjectAlbum(opt).catch(() => false)
      this.infoLoading = false
      if (res === false) return

      const data = res.rows?.[0] || {}
      data.fileName = data.displayName || item.fileName
      this.info = data
      this.currFile.fileInfo = data
    }
  }
}
</script>
